package cn.edu.sgu.www.mhxysy.controller.xingshi;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.xingshi.XingshiDTO;
import cn.edu.sgu.www.mhxysy.dto.xingshi.XingshiInlayDTO;
import cn.edu.sgu.www.mhxysy.entity.xingshi.Xingshi;
import cn.edu.sgu.www.mhxysy.pager.xingshi.XingshiPager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.xingshi.XingshiService;
import cn.edu.sgu.www.mhxysy.vo.except.AttributeVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "星石管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/xingshi", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class XingshiController {

	private final XingshiService xingshiService;

	@Autowired
	public XingshiController(XingshiService xingshiService) {
		this.xingshiService = xingshiService;
	}

	@ApiOperation("计算星石评分")
	@RequestMapping(value = "/compute", method = RequestMethod.POST)
	public JsonResult<Void> compute(
			@ApiParam(name = "xingshiId", value = "星石ID", required = true)
			@NotBlank(message = CustomMessages.XINGSHI_ID_NOT_NULL) String xingshiId) {
		xingshiService.compute(xingshiId);

		return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
	}

	@ApiOperation("星石镶嵌")
	@RequestMapping(value = "/inlay", method = RequestMethod.POST)
	public JsonResult<Void> inlay(@Validated XingshiInlayDTO xingshiInlayDTO) {
		xingshiService.inlay(xingshiInlayDTO);

		return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
	}

	@ApiOperation("添加星石")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated XingshiDTO xingshiDTO) {
		xingshiService.insert(xingshiDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID删除星石")
	@RequestMapping(value = "/deleteById", method = RequestMethod.POST)
	public JsonResult<Void> deleteById(
			@ApiParam(name = "id", value = "星石ID", required = true)
			@NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
		xingshiService.deleteById(id);

		return JsonResult.success(CustomMessages.DELETE_SUCCESS);
	}

	@ApiOperation("通过ID修改星石信息")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated XingshiDTO xingshiDTO) {
		xingshiService.updateById(xingshiDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("分页查询星石列表")
	@RequestMapping(value = "/selectByPage", method = RequestMethod.POST)
	public JsonResult<JsonPage<Xingshi>> selectByPage(XingshiPager pager) {
		Page<Xingshi> result = xingshiService.selectByPage(pager);

		return JsonResult.restPage(result);
	}

	@ApiOperation("通过星石ID查询星石属性")
	@RequestMapping(value = "/selectAttribute", method = RequestMethod.GET)
	public JsonResult<AttributeVO> selectAttribute(
			@ApiParam(name = "xingshiId", value = "星石ID", required = true)
			@NotBlank(message = CustomMessages.XINGSHI_ID_NOT_NULL) String xingshiId) {
		AttributeVO attributeVO = xingshiService.selectAttribute(xingshiId);

		return JsonResult.success(null, attributeVO);
	}

	@ApiOperation("通过宠物装备ID查询星石")
	@RequestMapping(value = "/selectByEquipmentId", method = RequestMethod.GET)
	public JsonResult<Xingshi> selectByEquipmentId(
			@ApiParam(name = "equipmentId", value = "通过宠物装备ID", required = true)
			@NotBlank(message = "宠物" + CustomMessages.CHONGWU_EQUIPMENT_ID_NOT_NULL) String equipmentId) {
		Xingshi xingshi = xingshiService.selectByEquipmentId(equipmentId);

		return JsonResult.success(null, xingshi);
	}

}